import datetime

class BaseModel:
    """数据模型基类"""
    
    def __init__(self):
        self.id = None
        self.create_time = None
        self.update_time = None
    
    def to_dict(self):
        """将模型转换为字典格式"""
        result = {}
        for key, value in self.__dict__.items():
            # 处理datetime对象
            if isinstance(value, datetime.datetime):
                result[key] = value.strftime('%Y-%m-%d %H:%M:%S')
            else:
                result[key] = value
        return result
    
    @classmethod
    def from_dict(cls, data):
        """从字典创建模型实例"""
        instance = cls()
        for key, value in data.items():
            setattr(instance, key, value)
        return instance